package ru.integrationmessagers.vk.rest;

import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ru.integrationmessagers.vk.model.domain.Friend;
import ru.integrationmessagers.vk.model.dto.mapper.self.FriendMapper;
import ru.integrationmessagers.vk.model.dto.self.FriendDto;
import ru.integrationmessagers.vk.model.response.self.Response;
import ru.integrationmessagers.vk.services.FriendService;

import java.util.List;

import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

@RestController
@RequestMapping("/friends")
@RequiredArgsConstructor
public class FriendsController {

    private final FriendService friendService;
    private final FriendMapper mapper;

    @GetMapping(value = "/get_all", produces = {APPLICATION_JSON_VALUE})
    public ResponseEntity<Response<FriendDto>> getAll() {
        List<Friend> friends = friendService.getFriends();


        List<FriendDto> dtoList = mapper.toListDto(friends);
        return ResponseEntity.ok(
                Response.from(dtoList)
        );
    }
}
